package com.qf.flash.ui.business.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.qf.flash.R;
import com.qf.flash.constant.FlashCodes;
import com.qf.flash.http.response.ShopOrderBean;
import com.qf.flash.utils.ImageLoader;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;

/**
 * 创建日期：2020/3/14 on 20:50
 * 描述:
 * 作者:戴旭东
 */
public class MyBillItem extends BaseRViewItem<ShopOrderBean> {
    @Override
    public int getItemLayout() {
        return R.layout.item_my_bill;
    }

    @Override
    public void convert(RViewHolder holder, ShopOrderBean entity, int position, int itemSize) {
        holder.setOnClickListener(R.id.tv_action)
                .setOnClickListener(R.id.cv_group);
        Context context = holder.getmConvertView().getContext();

        holder.setText(R.id.tv_situation, entity.getOrderTip())
                .setText(R.id.tv_action, getActionName(entity))
                .setText(R.id.tv_count, context.getString(R.string.percent, entity.getPayedNum(), entity.getNeedNum()))
                .setText(R.id.tv_name, entity.getTeamName())
                .setText(R.id.tv_group_no, entity.getOrderNumber())
                .setText(R.id.tv_nick_name, entity.getCaptainName())
                .setText(R.id.tv_time, entity.getCreateDate())
                .setText(R.id.tv_bus_name, entity.getShop().getName())
                .setText(R.id.tv_address, entity.getShop().getLocation())
                .setText(R.id.tv_type, entity.getTypeName());
        ImageView view = holder.getView(R.id.iv_img);
        ImageLoader.loadRoundCorners(view.getContext(), entity.getPlayImage(), view, 5);
    }

    private String getActionName(ShopOrderBean bean) {
        String orderState = bean.getOrderState();
        switch (orderState) {
            //待付定金
            case FlashCodes.ORDER_STATE_DFDJ:
                break;
            //待组队
            case FlashCodes.ORDER_STATE_DZD:
                return "完成组队";
            //待开始(完成组队)
            case FlashCodes.ORDER_STATE_WCZD:
                //免费的情况， 可以直接开始
                if (TextUtils.equals(bean.getIsFree(), "1")) {
                    return "开始游戏";
                } else if (bean.getIsSetRest() != 1) {
                    //没有设置尾款， 去设置页面
                    return "设置尾款";
                } else {
                    //开始游戏
                    return "开始游戏";
                }

            //待结束 todo
            case FlashCodes.ORDER_STATE_DJS:
                return "结束游戏";
            //4已完成  去设置担当
            case FlashCodes.ORDER_STATE_YWC:
                return "设置担当";
        }
        return "";
    }
}
